<template>
    <div>
      <h3 style="text-align: center;">新闻详情</h3>
      <div>新闻ID: {{ newsInfo.id }}</div>
      <div>新闻标题: {{ newsInfo.title }}</div>
      <div>新闻内容: {{ newsInfo.content }}</div>
    </div>
  </template>
  
  <script>
  export default {
    name: 'NewsDetail',
    data() {
      return {
        newsId: 0,
        newsInfo: {}
      }
    },
    mounted() {
      this.getNewsInfo();
    },
    beforeRouteEnter(to, from, next) {
      next();
    },
    beforeRouteLeave(to, from, next) {
      next();
    },
    beforeRouteUpdate(to, from, next) {
      next();
      this.getNewsInfo();
    },
    methods: {
      getNewsInfo() {
        this.newsId = this.$route.params.id;
        this.newsInfo = {
          id: this.newsId,
          title: '新闻标题-' + this.newsId,
          content: '新闻内容-' + this.newsId
        };
      }
    }
  };
  </script>